﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Model.Repositories.Interfaces;
using DomenModel;
using NSubstitute;
using Model.Service;
using Infrastructure.Service;
using System.Linq;


namespace OmsTestProject.AdministratorServiceTests
{
    [TestFixture]
    public class AdministratorServiceTestsWithSimpleLogic
    {
        private User userExpected;
        private List<Role> rolesExpected;
        private IUserCrud userMock;
        private ICrud<Role> roleMock;
        private IAdministratorService admService;
        
        [SetUp]
        public void Setup()
        {
            userExpected = new User { LoginName = "admin", IsActive = true };
            rolesExpected = new List<Role> {new Role { Name = "administrator" }};
            userMock = Substitute.For<IUserCrud>();
            roleMock = Substitute.For<ICrud<Role>>();
            admService = new AdministratorService(userMock, roleMock);
        }

        [Test]
        public void AdministratorService_GetUser_ReturnedValueVerified() 
        {
            String testLogin = "admin";
            userMock.GetByLogin(testLogin).Returns(userExpected);

            User actual = admService.GetUser(testLogin);
            
            Assert.AreEqual(userExpected, actual);        
        }

        [Test]
        public void AdministratorService_GetRoles_ReturnedValueVerified()
        {
            
            roleMock.GetCollection().Returns(rolesExpected);

            List<Role> actual = admService.GetRoles();

            Assert.AreEqual(rolesExpected, actual);
        }

      
        [Test]
        [TestCase(true)]
        [TestCase(false)]
        public void AdministratorService_CreateUser(bool isExists)
        {
            String testLogin = "admin";

            if (isExists)
            {
                userMock.GetByLogin(testLogin).Returns(userExpected);
                Assert.False(admService.CreateUser(userExpected));
            }
            else 
            {
                Assert.True(admService.CreateUser(userExpected));
            }
            
        }

    }

}

